<?php

namespace app\index\logic;

require_once APP_PATH . 'index/sdk/aliyun-oss-php-sdk-master/autoload.php';

use app\Api;
use OSS\OssClient;
use OSS\Core\OssException;

class Oss extends Api
{
    private $ossClient;

    public function __construct()
    {
        parent::__construct();
        $this->ossClient = new OssClient(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, OSS_ENDPOINT);
        $this->ossClient->setTimeout(3600); //设置请求超时时间seconds
        $this->ossClient->setConnectTimeout(10);//设置连接超时时间seconds
    }

    /**
     * 文件上传
     * @param $bucket
     * @param $object
     * @param $filePath
     */
    function uploadFile($object, $filePath, $bucket = 'jiegege')
    {
        try {
            $this->ossClient->uploadFile($bucket, $object, $filePath);
        } catch (OssException $e) {
            print($e->getMessage());
        }
        return true;
    }
}
